
#include "mainwindow.h"
#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
#include <QRect>
#include <QFont>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    /* 获取屏幕的分辨率，Qt官方建议使用这
     * 种方法获取屏幕分辨率，防上多屏设备导致对应不上
     * 注意，这是获取整个桌面系统的分辨率
     */
    QList <QScreen *> list_screen =  QGuiApplication::screens();

    /* 如果是ARM平台，直接设置大小为屏幕的大小 */
#if __arm__
    /* 重设大小 */
    this->resize(list_screen.at(0)->geometry().width(),
                 list_screen.at(0)->geometry().height());
   
   
#else
    /* 否则则设置主窗体大小为800x480 */
    this->resize(800, 480);
#endif

    
    label = new QLabel(this);

    /* 居中显示 */
    label->setGeometry(20 ,20,this->width()-50,this->height()-50);
    //label->setText("显示ICM20608的数据,学号+姓名:ck202005200101cyj");
    //label->setAlignment(Qt::AlignCenter);
    QFont font("微软雅黑",22,QFont::Bold,true);
    label->setFont(font);

    icm20608 = new Icm20608(this);
    icm20608->setCapture(true);    
    
    connect(icm20608, SIGNAL(icm20608DataChanged()),this, SLOT(getICM20608Data()));
    
}

MainWindow::~MainWindow()
{
}

void MainWindow::getICM20608Data()
{
    
    QString gxdata = icm20608->gxdata;
    QString gydata = icm20608->gydata;
    QString gzdata = icm20608->gzdata;
    QString axdata = icm20608->axdata;
    QString aydata = icm20608->aydata;
    QString azdata = icm20608->azdata;
    QString tempdata = icm20608->tempdata;
    QString ID = "学号+姓名:ck202005200101cyj";
    QString  values;
    values = QString("显示ICM20608的数据\n gxdata:%1\n gyxdata:%2\n gzdata:%3\n axdata:%4\n aydata:%5\n azdata:%6\n tempdata:%7 \n ID:%8\n").arg(gxdata).arg(gydata).arg(gzdata).arg(axdata).arg(aydata).arg(azdata).arg(tempdata).arg(ID);
    //values.sprintf("gxdata:%s\n gyxdata:%s\n gzdata:%s\n axdata:%s\n aydata:%s\n azdata:%s\n tempdata:%s\n",gxdata, gydata,gzdata,axdata,aydata,azdata,tempdata);
    label->setText(values);
    
   
}
